11 const int MAXN
= 1000, MAXC
= 100;
16 edge(int I
, int G
, int W
) : i(I
), g(G
), w(W
) {}
17 bool operator < (const edge
&that
) const {
22 int p
[MAXN
], d
[MAXN
][MAXC
+1], n
, visited
, maxQSize
;
26 int dijkstra(const int &start
, const int &end
, const int &c
){
27 for (int i
=0; i
<n
; ++i
)
28 for (int j
=0; j
<=c
; ++j
)
31 priority_queue
<edge
> q
;
32 q
.push(edge(start
, 0, 0));
37 maxQSize
= max(maxQSize
, (int)q
.size());
42 //printf("popped <%d, %d, %d>\n", u.i, u.g, u.w);
46 if (d
[u
.i
][u
.g
] < u
.w
) continue;
50 //I can buy another gallon and stay where I am
51 if (u
.g
< c
&& u
.w
+ p
[u
.i
] < d
[u
.i
][u
.g
+1]){
52 d
[u
.i
][u
.g
+1] = u
.w
+ p
[u
.i
];
53 q
.push(edge(u
.i
, u
.g
+1, u
.w
+ p
[u
.i
]));
56 //Now try to reach each other node as long as I have enough gas
57 vector
<edge
> &v
= g
[u
.i
];
58 for (int j
=0; j
<v
.size(); ++j
){
59 int distance
= v
[j
].w
;
60 int neighbor
= v
[j
].i
;
62 int new_gas
= u
.g
- distance
;
63 if (u
.w
< d
[neighbor
][new_gas
]){
64 d
[neighbor
][new_gas
] = u
.w
;
65 q
.push(edge(neighbor
, new_gas
, u
.w
));
76 scanf("%d %d", &n
, &m
);
77 for (int i
=0; i
<n
; ++i
){
83 scanf("%d %d %d", &u
, &v
, &d
);
84 g
[u
].push_back(edge(v
, 0, d
));
85 g
[v
].push_back(edge(u
, 0, d
));
92 scanf("%d %d %d", &c
, &s
, &e
);
95 int t
= dijkstra(s
, e
, c
);
99 printf("impossible\n");
101 printf(" Visited %d states with maximum queue size of %d\n", visited
, maxQSize
);